<%
   current_display_id = "sources_#{rand(100)}"
%>

<table id="<%= current_display_id %>" class="sources2 code" cellpadding="0" cellspacing="0">

    <script>
      $j("#<%= current_display_id %>").on("click", "span.sym", {id: "<%= current_display_id.to_s() %>"}, highlightUsages);
    </script>

        <%
           colspan=2
           gray_colspan=1
           white_colspan=0
           if display_manual_violation_form
             colspan+=1
             gray_colspan+=1
           end
           if scm_available
             colspan+=1
             gray_colspan+=1
           end
           if display_coverage
             colspan+=2
             white_colspan+=2
           end

           current_revision=nil
           previous_hidden=false
           first_section=true
           has_displayed_lines=false
           lines.each_with_index do |line, index|
             if line.hidden? && !expanded
               previous_hidden=true
               next
             end

             if previous_hidden && !first_section
               current_revision=nil

           %>

        <%= render :partial => "shared/source_new_section", :locals => {:colspan => colspan} %>
      <%
         end
         previous_hidden=false
         first_section=false

         status=hits_status=conditions_status=''
         if line.displayed?
           has_displayed_lines=true
           if display_coverage && line.hits
             hits_status=(line.hits>0 ? 'ok' : 'ko')
             if line.conditions && line.conditions>0 && line.covered_conditions
               if line.covered_conditions==0
                 status='ko'
                 conditions_status='ko'
               elsif line.covered_conditions==line.conditions
                 status=''
                 conditions_status='ok'
               else
                 conditions_status='warn'
                 status='warn'
               end
             elsif line.hits
               status=(line.hits>0 ? '' : 'ko')
             end
           elsif display_issues && line.issues?
             status="ko"
           elsif line.has_focus
             status="ko"
           end
         end
      %>

      <tr class="row pos<%= index+1 -%>">

          <% if display_manual_violation_form %>
            <%= render :partial => "shared/source_issue_form", :locals => { :resource_id => resource.id,
                                                                                :index => index,
                                                                                :gray_colspan => gray_colspan,
                                                                                :white_colspan => white_colspan} %>
          <% end %>

          <% if scm_available
               if current_revision!=line.revision
                 current_revision=line.revision
                 title = "Revision #{h(line.revision)}"
          %>

              <%= render :partial => "shared/source_scm", :locals => {:line => line, :title => title} %>

            <% else %>
              <td class="scm"></td>
            <% end %>

          <% end %>

          <%= render :partial => "shared/source_line_numbers", :locals => {:index => line.id} %>

          <% if display_coverage %>
            <%= render :partial => "shared/source_coverage", :locals => {:line => line,
                                                                          :statuses => {:hits => hits_status, :conditions => conditions_status},
                                                                          :index => index,
                                                                          :resource_key => snapshot.resource.key} %>
          <% end %>

          <%= render :partial => "shared/source_code", :locals => {:code => line.source, :status => status} %>

      </tr>

      <% if display_issues && line.issues? %>
        <%= render :partial => "shared/source_issues", :locals => { :line => line,
                                                                    :display_manual_violation_form => display_manual_violation_form,
                                                                    :scm_available => scm_available} %>
      <% end %>

    <% end %>
</table>

<% if filtered && !has_displayed_lines %>
  <% if display_issues && !has_global_issues %>
    <%= render :partial => 'shared/no_issues' -%>
  <% elsif display_coverage  %>
    <p style="padding: 10px"><%= message('no_lines_match_your_filter_criteria') -%></p>
  <% end %>
<% end %>



